package client;

import client.communication.Log;
import client.sharedRessources.Constants.EventType;
import client.sharedRessources.Order;

public class CellFacade implements IMesFacade
{
	private CellMES_Mediator mediator;
	private static CellFacade instance;
	
	private CellFacade()
	{
		mediator = CellMES_Mediator.getInstance();
	}
	
	public static CellFacade getInstance()
	{
		if (instance == null)
			instance = new CellFacade();
		return instance;
	}

	public void sendLogPML_Idle(long time, String comment)
	{
		this.sendLog(EventType.PML_Idle, time, comment);
	}

	public void sendLogPML_Execute(long time, String comment)
	{
		this.sendLog(EventType.PML_Execute, time, comment);
	}

	public void sendLogPML_Complete(long time, String comment)
	{
		this.sendLog(EventType.PML_Complete, time, comment);
	}

	public void sendLogPML_Held(long time, String comment)
	{
		this.sendLog(EventType.PML_Held, time, comment);
	}

	public void sendLogPML_Suspended(long time, String comment)
	{
		this.sendLog(EventType.PML_Suspended, time, comment);
	}

	public void sendLogPML_Aborted(long time, String comment)
	{
		this.sendLog(EventType.PML_Aborted, time, comment);
	}

	public void sendLogPML_Stopped(long time, String comment)
	{
		this.sendLog(EventType.PML_Stopped, time, comment);
	}

	public void sendLogOrder_Start(long time, String comment)
	{
		this.sendLog(EventType.Order_Start, time, comment);
	}
	
	/**
	 * 
	 * @param time
	 * @param comment For Order_Start the order number should be given in the comment.
	 * @param ticket
	 */
	private void sendLog(EventType event, long time, String comment)
	{
		mediator.sendLog(new Log(event, time, comment));
	}
	
	public Order getNewOrder()
	{
		return mediator.getNewOrder();
	}
	
	public void orderCompleted(long time, String comment, String ticket)
	{
		String orderID = comment;
		mediator.orderDone(orderID, ticket);
		System.out.println();
		mediator.sendLog(new Log(EventType.Order_Done, time, comment));
	}
}
